package com.tz.online.order.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.tz.online.entity.Address;
import com.tz.online.entity.User;
import com.tz.online.order.service.IOrderService;
import com.tz.online.util.BeanFactory;

/**
 * 接收添加新地址请求
 * @author Administrator
 *
 */
@WebServlet(name="saveAddress",urlPatterns="/permission/order/saveAddress")
public class SaveAddressAction extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = -3970115226161604448L;
	IOrderService os = (IOrderService) BeanFactory.getBean("orderService");
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		PrintWriter out = resp.getWriter();
		
		try {
			Address a = new Address();
			a.setArea(req.getParameter("baseAddress"));
			a.setDetailAddres(req.getParameter("detailAddress"));
			a.setEmailCode(req.getParameter("code"));
			a.setIsDefault(req.getParameter("isDefault"));
			a.setReciver(req.getParameter("reciver"));
			a.setTel(req.getParameter("tel"));
			a.setUser((User)req.getSession().getAttribute("userInfo"));
			
			os.saveAddress(a);
			out.print("1");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			out.print("0");
			e.printStackTrace();
		}
		
		/*
		//接收地址信息
		Address a = new Address();
		
		is.saveAddress(a);
		
		out.print(a.getAddressId());
		*/
	}
	
	
}
